public class Person {
	public String uri { get; set; }
	public String name { get; set; }
	public String email { get; set; }
	public String personType { get; set; }
	public Map<String, String> extensions { get; set; }
	
	public Person() {
		extensions = new Map<String, String>();
	}
	 
	public Person(XmlStreamReader reader, String rootName) {
		String nodeName = rootName;
		String nodeText;
		personType = rootName;
		extensions = new Map<String, String>();
		
		while (reader.hasNext()) {
			try {
		        if (reader.getEventType() == XmlTag.START_ELEMENT) {
					nodeName = reader.getLocalName();
					nodeText = '';
				} else if (reader.getEventType() == XmlTag.CHARACTERS) {
					if ( ! reader.isWhitespace()) { 
	                    nodeText += reader.getText();  // add text to current element
						System.debug(LoggingLevel.FINE, '\n\nCollecting the ' + nodeName + ' values: ' + nodeText + '\n');
	                }
		        } else if (reader.getEventType() == XmlTag.END_ELEMENT) {
					System.debug(LoggingLevel.FINE, '\n\nEND_ELEMENT nodeName: ' + reader.getLocalName() + ' - rootName: ' + rootName + '\n');
		        	if (reader.getLocalName() == rootName) {
		        		return;
		        	}
		   			if (nodeName == 'email') {
		   				email = nodeText;
					} else if (nodeName == 'name') {
						name = nodeText;
					} else if (nodeName == 'uri') {
						uri = nodeText;
					} else { 
						extensions.put(nodeName, nodeText);
		   			}
		        }
			} catch (Exception e) {
				System.debug(LoggingLevel.ERROR, '\n\nError parsing author node...\nevent: ' + reader.getEventType() + '\ntagname: ' + nodeName + '\ntag value: ' + nodeText + '\n');
			} finally {
				reader.next();
			}
		}				
	}
	
	public String toAPP() {
		String output = '<' + personType + '>\n';
		if (uri != null) output += '<uri>' + uri + '</uri>\n';
		if (name != null) output += '<name>' + name + '</name>\n';
		if (email != null) output += '<email>' + email + '</email>\n';
		for (String key : extensions.keySet()) {
			output += '<snx:' + key + '>' + extensions.get(key) + '</snx:' + key + '>\n';
		}
		output += '</' + personType + '>\n';
		return output;
	}

	public void addExtension(String key, String value) {
		extensions.put(key, value);
	}
}